package com.neusoft.neuiotms.dcom.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.neusoft.bizcore.web.dto.result.PageResultDTO;
import com.neusoft.bizcore.web.dto.result.ResultDTO;
import com.neusoft.bizcore.web.dto.result.ResultListDTO;
import com.neusoft.bizcore.web.support.Searchable;
import com.neusoft.neuiotms.dcom.dto.PriorityDTO;
import com.neusoft.neuiotms.dcom.service.PriorityService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * @author WYS
 * @date 2020年8月18日 下午2:03:59
 */
@Api(tags = "优先级管理")
@RestController
@RequestMapping(value = "/api/w/priority")
public class PriorityController {
    @Autowired

    private PriorityService priorityService;

    @ApiOperation("查询所有优先级")
    @GetMapping
    public ResultListDTO<PriorityDTO> index(final Searchable searchable) {
        return ResultListDTO.success(this.priorityService.index(searchable));
    }

    @ApiOperation("分页查询优先级")
    @GetMapping("/p")
    public PageResultDTO<PriorityDTO> page(final Searchable searchable, final Pageable pageable) {
        return PageResultDTO.success(this.priorityService.page(searchable, pageable));
    }

    @ApiOperation("新增优先级")
    @PostMapping
    public ResultDTO<PriorityDTO> create(@RequestBody final PriorityDTO dto) {
        return ResultDTO.success(this.priorityService.create(dto));
    }

    @ApiOperation("更新优先级")
    @PutMapping("/{id}")
    public ResultDTO<PriorityDTO> update(@PathVariable final Long id, @RequestBody final PriorityDTO dto) {
        return ResultDTO.success(this.priorityService.update(id, dto));
    }

    @ApiOperation("查看优先级")
    @GetMapping("/{id}")
    public ResultDTO<PriorityDTO> details(@PathVariable final Long id) {
        return ResultDTO.success(this.priorityService.detail(id));
    }

    @ApiOperation("根据影响范围和紧急程度查询优先级")
    @GetMapping("/getByParams/{coverageInfluence}/{urgency}")
    public ResultListDTO<PriorityDTO> getByParams(@PathVariable final String coverageInfluence,
            @PathVariable final String urgency) {
        final Searchable Searchable = new Searchable();
        Searchable.put("coverageInfluence", coverageInfluence);
        Searchable.put("urgency", urgency);
        return ResultListDTO.success(this.priorityService.index(Searchable));
    }

    @ApiOperation("删除优先级")
    @DeleteMapping("/{id}")
    public ResultDTO<Void> delete(@PathVariable final Long id) {
        this.priorityService.delete(id);
        return ResultDTO.success();
    }

}
